<script setup lang="ts">
import { ref } from 'vue'
import { getAssetsImge } from '/@/utils/getImge'

interface UserProfile {
  name: string
  avatar: string
  badge: string
  school: string
  year: string
  major: string
  location: string
  bio: string
  completeness: number
  stats: {
    obtains: number
    fans: number
    follows: number
    views: number
  }
}

const userProfile = ref<UserProfile>({
  name: 'jokerak',
  avatar: getAssetsImge('avatar.svg'),
  badge: '出师生',
  school: '太原理工大学',
  year: '2024',
  major: 'Java',
  location: '福建',
  bio: '苦而不言，喜而不语',
  completeness: 85,
  stats: {
    obtains: 45,
    fans: 1,
    follows: 5,
    views: 189
  }
})

const tabs = ref([
  { name: '发布(3)', key: 'posts' },
  { name: '评论(9)', key: 'comments' },
  { name: '投递记录', key: 'applications' },
  { name: '刷题', key: 'exercises' },
  { name: '收藏', key: 'collections' }
])

const activeTab = ref('posts')

const handleEditProfile = () => {
  // 处理编辑个人资料
}

const handleVerify = () => {
  // 处理认证
}
</script>

<template>
  <div class="profile-container">
    <!-- 个人信息卡片 -->
    <div class="profile-card">
      <div class="profile-header">
        <div class="avatar-section">
          <img :src="userProfile.avatar" :alt="userProfile.name" class="avatar">
          <span class="badge">{{ userProfile.badge }}</span>
        </div>

        <div class="user-info">
          <div class="name-section">
            <h1>{{ userProfile.name }}</h1>
            <button class="verify-btn" @click="handleVerify">
              暂未认证，去认证 >
            </button>
          </div>

          <div class="basic-info">
            <div class="tag-item">
              <i class="fas fa-school"></i>
              <span class="tag-text">{{ userProfile.school }}</span>
            </div>
            <div class="tag-item">
              <i class="fas fa-calendar"></i>
              <span class="tag-text">{{ userProfile.year }}</span>
            </div>
            <div class="tag-item">
              <i class="fas fa-code"></i>
              <span class="tag-text">{{ userProfile.major }}</span>
            </div>
            <div class="tag-item">
              <i class="fas fa-map-marker-alt"></i>
              <span class="tag-text">{{ userProfile.location }}</span>
            </div>
          </div>

          <div class="bio">{{ userProfile.bio }}</div>

          <div class="profile-completeness">
            <div class="completeness-text">
              个人资料完善度：{{ userProfile.completeness }}%
              <button class="edit-btn" @click="handleEditProfile">
                去编辑
              </button>
            </div>
            <div class="progress-bar">
              <div
                class="progress"
                :style="{ width: `${userProfile.completeness}%` }"
              ></div>
            </div>
          </div>
        </div>

        <div class="profile-actions">
          <button class="resume-btn">
            我的简历
          </button>
          <button class="verify-test-btn">
            去试试
          </button>
        </div>
      </div>

      <div class="stats-bar">
        <div class="stat-item">
          <div class="stat-value">{{ userProfile.stats.obtains }}</div>
          <div class="stat-label">获赞</div>
        </div>
        <div class="stat-item">
          <div class="stat-value">{{ userProfile.stats.fans }}</div>
          <div class="stat-label">粉丝</div>
        </div>
        <div class="stat-item">
          <div class="stat-value">{{ userProfile.stats.follows }}</div>
          <div class="stat-label">关注</div>
        </div>
        <div class="stat-item">
          <div class="stat-value">{{ userProfile.stats.views }}</div>
          <div class="stat-label">看过我</div>
        </div>
      </div>
    </div>

    <!-- 内容标签页 -->
    <div class="content-tabs">
      <div class="tabs-header">
        <button
          v-for="tab in tabs"
          :key="tab.key"
          class="tab-btn"
          :class="{ active: activeTab === tab.key }"
          @click="activeTab = tab.key"
        >
          {{ tab.name }}
        </button>
      </div>

      <!-- 会员广告 -->
      <div class="vip-banner">
        <div class="vip-info">
          <i class="fas fa-crown"></i>
          牛客会员
          <span class="vip-badge">未开通</span>
        </div>
        <div class="vip-text">
          求职路上牛客为你保驾护航
        </div>
        <button class="vip-btn">
          立即开通
        </button>
      </div>

      <!-- 创作者中心 -->
      <div class="creator-section">
        <div class="creator-header">
          <h3>创作者中心</h3>
          <a href="#" class="more-link">进入 ></a>
        </div>
        <div class="creator-actions">
          <button class="action-btn">
            <i class="fas fa-pen"></i>
            发动态
          </button>
          <button class="action-btn">
            <i class="fas fa-edit"></i>
            写文章
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.profile-container {
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px;
}

.profile-card {
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.profile-header {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.avatar-section {
  position: relative;
}

.avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
}

.badge {
  position: absolute;
  bottom: 0;
  right: 0;
  background-color: #1890ff;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.user-info {
  flex: 1;
}

.name-section {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.name-section h1 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.verify-btn {
  background: none;
  border: none;
  color: #1890ff;
  cursor: pointer;
  font-size: 14px;
}

.basic-info {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.tag-item {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background-color: #f5f7fa;
  border-radius: 16px;
  transition: all 0.3s ease;
}

.tag-item:hover {
  background-color: #e6f7ff;
  transform: translateY(-1px);
}

.tag-item i {
  font-size: 14px;
  margin-right: 6px;
}

.tag-item:nth-child(1) {
  color: #1890ff;
  background-color: #e6f7ff;
}

.tag-item:nth-child(2) {
  color: #52c41a;
  background-color: #f6ffed;
}

.tag-item:nth-child(3) {
  color: #722ed1;
  background-color: #f9f0ff;
}

.tag-item:nth-child(4) {
  color: #fa8c16;
  background-color: #fff7e6;
}

.tag-item i {
  opacity: 0.8;
}

.tag-text {
  font-size: 13px;
  font-weight: 500;
}

/* 添加动画效果 */
.tag-item {
  position: relative;
  overflow: hidden;
}

.tag-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    120deg,
    transparent,
    rgba(255, 255, 255, 0.6),
    transparent
  );
  transform: translateX(-100%);
}

.tag-item:hover::after {
  transform: translateX(100%);
  transition: transform 0.6s;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .basic-info {
    gap: 8px;
  }

  .tag-item {
    padding: 4px 10px;
  }

  .tag-text {
    font-size: 12px;
  }
}

.bio {
  color: #666;
  margin-bottom: 16px;
  font-size: 14px;
}

.profile-completeness {
  margin-bottom: 16px;
}

.completeness-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  color: #666;
  font-size: 14px;
}

.edit-btn {
  background: none;
  border: none;
  color: #1890ff;
  cursor: pointer;
}

.progress-bar {
  height: 4px;
  background-color: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
}

.progress {
  height: 100%;
  background-color: #1890ff;
  transition: width 0.3s ease;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.resume-btn,
.verify-test-btn {
  padding: 8px 24px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.resume-btn {
  background-color: #1890ff;
  color: white;
}

.resume-btn:hover {
  background-color: #40a9ff;
}

.verify-test-btn {
  background-color: #f5f5f5;
  color: #666;
}

.verify-test-btn:hover {
  background-color: #e8e8e8;
}

.stats-bar {
  display: flex;
  border-top: 1px solid #f0f0f0;
  padding-top: 20px;
}

.stat-item {
  flex: 1;
  text-align: center;
  border-right: 1px solid #f0f0f0;
}

.stat-item:last-child {
  border-right: none;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #666;
}

.content-tabs {
  background-color: #fff;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.tabs-header {
  display: flex;
  gap: 32px;
  margin-bottom: 20px;
  border-bottom: 1px solid #f0f0f0;
}

.tab-btn {
  background: none;
  border: none;
  padding: 12px 0;
  color: #666;
  cursor: pointer;
  font-size: 14px;
  position: relative;
}

.tab-btn.active {
  color: #1890ff;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #1890ff;
}

.vip-banner {
  background: linear-gradient(135deg, #ffd700 0%, #ffb700 100%);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.vip-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #333;
  font-weight: 500;
}

.vip-info i {
  color: #fff;
}

.vip-badge {
  background-color: rgba(255, 255, 255, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.vip-text {
  color: #333;
  font-size: 14px;
}

.vip-btn {
  background-color: #fff;
  color: #333;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.vip-btn:hover {
  background-color: #f8f8f8;
}

.creator-section {
  background-color: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
}

.creator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.creator-header h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.more-link {
  color: #666;
  text-decoration: none;
  font-size: 14px;
}

.creator-actions {
  display: flex;
  gap: 12px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background-color: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background-color: #f5f5f5;
}

@media (max-width: 768px) {
  .profile-header {
    flex-direction: column;
  }

  .basic-info {
    flex-wrap: wrap;
    gap: 12px;
  }

  .stats-bar {
    flex-wrap: wrap;
  }

  .stat-item {
    flex: 1 0 50%;
    border-right: none;
    border-bottom: 1px solid #f0f0f0;
    padding: 12px 0;
  }

  .stat-item:nth-last-child(-n+2) {
    border-bottom: none;
  }
}
</style>
